﻿using System;

using Moe.ECamel.Common.Entities;
using Moe.ECamel.Client.Controllers;
using Moe.ECamel.Client.WinForms.Common;

namespace Moe.ECamel.Client.WinForms.Controls
{
	public partial class RentalDetailsControl : ECamelUserControl
	{
		public RentalDetailsControl()
		{
			InitializeComponent();
		}

		private DetailsMode _detailsMode;
		public DetailsMode DetailsMode
		{
			get { return this._detailsMode; }
			set
			{
				this._detailsMode = value;
				this.IsActiveCheckBox.Enabled = (this._detailsMode != DetailsMode.View);
				this.ActualReturnDateDateTimePicker.Enabled = (this._detailsMode != DetailsMode.View);
			}
		}

		public void Bind(Rental entity)
		{
			RentalBindingSource.DataSource = entity;
			RentalIdTextBox.Bind(RentalBindingSource, "RentalId");
			CatalogNumberTextBox.Bind(RentalBindingSource, "ItemCatalogNumber");
			TitleTextBox.Bind(RentalBindingSource, "ItemTitle");
			ItemTypeComboBox.Bind(RentalBindingSource, "ItemTypeId", ECamelHelper.ItemTypesList, "ItemTypeName", "ItemTypeId");
			RentalDateDateTimePicker.Bind(RentalBindingSource, "RentalDate");
			ExpectedReturnDateDateTimePicker.Bind(RentalBindingSource, "ExpectedReturnDate");
			ActualReturnDateDateTimePicker.Bind(RentalBindingSource, "ActualReturnDate");
			IsActiveCheckBox.Bind(RentalBindingSource, "Active");
		}

		public void CancelEdit()
		{
			this.RentalBindingSource.CancelEdit();
		}
	}
}
